<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="div1"></div>
    <script type="text/javascript">
        window.onload = function () {
            var div1 = document.getElementById("div1");
            function daojishi() {
                var now = new Date()
                var future = new Date(2018,7,1,0,0,0);
                alert(future-now)
                var lefts = parseInt((future-now)/1000);
                var day = parseInt(lefts/86400);
                var hour = parseInt(lefts%86400/3600);
                var min = parseInt(lefts%86400%3600/60);
                var sec = lefts%60;
                str = '距离2018年9月1日晚0点还剩下'+day+'天'+hour+'时'+min+'分'+sec+'秒';
                div1.innerHTML = str
            }
            daojishi()
            setInterval(daojishi,1000)
        }
    </script>

</body>
</html>